package wzc.design_pattern.creation.singleton.reflection;

import wzc.design_pattern.creation.singleton.DoubleCheckLocking;

import java.lang.reflect.Constructor;

/**
 * @Author 王振川
 * @Date 2025/7/20
 * @Description 反射攻击创建多个实例
 */

public class ReflectionAttack {
    public static void main(String[] args) throws Exception {
        DoubleCheckLocking instance = DoubleCheckLocking.getInstance();

        Constructor<DoubleCheckLocking> declaredConstructor = DoubleCheckLocking.class.getDeclaredConstructor();
        declaredConstructor.setAccessible(true);
        DoubleCheckLocking doubleCheckLocking = declaredConstructor.newInstance();

        System.out.println(instance);
        System.out.println(doubleCheckLocking);
        System.out.println(instance == doubleCheckLocking);
    }
}
